package proxypattern.test;

import proxypattern.entity.GumballMonitor;
import proxypattern.entity.RemoteGumballMachine;

import java.net.MalformedURLException;
import java.rmi.RemoteException;
import java.rmi.*;

/**
 * 糖果机监视器
 *
 * @author yaojianfeng
 */
public class GumballMonitorTestDrive {
    public static void main(String[] args) throws RemoteException {

        String[] location = {
                "rmi://santafe.mightygumball.com/gumballmachine",
                "rmi://boulder.mightygumball.com/gumballmachine",
                "rmi://seattle.mightygumball.com/gumballmachine",
                "rmi://jiankanglu.mightygumball.com/gumballmachine"
        };

        GumballMonitor[] monitors  = new GumballMonitor[location.length];


        for (int i = 0; i < location.length; i++) {
            try {
                RemoteGumballMachine machine = (RemoteGumballMachine) Naming.lookup(location[i]);
                monitors[i] = new GumballMonitor(machine);
            } catch (NotBoundException e) {
                e.printStackTrace();
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
        }

        for (int i = 0; i < monitors.length; i++) {
            monitors[i].report();

        }

        /*RemoteGumballMachine gumballMachine = RemoteGumballMachine.getInstance();
        gumballMachine.setCount(10);
        gumballMachine.setLocation("河北石家庄青园街");
        GumballMonitor monitor = new GumballMonitor(gumballMachine);
        monitor.report();
        gumballMachine.insertQuarter();
        gumballMachine.turnCrank();
        monitor.report();
        for (int i = 0; i < 10; i++) {
            gumballMachine.insertQuarter();
            gumballMachine.turnCrank();
            monitor.report();

        }*/
    }
}
